package com.yhcnet.blog.controller;

import com.yhcnet.blog.pojo.Word;
import com.yhcnet.blog.reponse.Resp;
import com.yhcnet.blog.service.WordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
@RequestMapping("/word")
public class WordController {
    @Autowired
    WordService wordService;

    /**
     * 先判断用户是否登录
     * @return
     */
    @RequestMapping("/say")
    public Resp say(@RequestBody Word word){
        if(word == null) return Resp.loginFail();
        if(wordService.say(word)) return Resp.OK();
        return Resp.loginFail();
    }

    @RequestMapping("/getW")
    public Resp getW(){
        return Resp.OK(wordService.gertW());
    }
}
